package com.zhilianbao.leyaogo.ui.adapter.home;

import android.app.Activity;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.bql.baseadapter.recycleView.QuickRcvAdapter;
import com.bql.baseadapter.recycleView.QuickRcvHolder;
import com.bql.utils.NumberUtlis;
import com.zhilianbao.leyaogo.R;
import com.zhilianbao.leyaogo.http.convert.GsonConvert;
import com.zhilianbao.leyaogo.model.response.home.SpecialActivityHotList;
import com.zhilianbao.leyaogo.model.response.home.SpecialActivityInfo;
import com.zhilianbao.leyaogo.utils.ImageUtils;
import com.zhilianbao.leyaogo.utils.Utils;

import java.util.List;

/**
 * ClassName: SpecialActivityHotAdapter <br>
 * Description: <br>
 * Author: Cyarie <br>
 * Created: 2016/12/13 14:08 <br>
 * Update Time：<br>
 * Update Description：<br>
 */
public class SpecialActivityHotAdapter extends QuickRcvAdapter<SpecialActivityInfo.MallActivityPageVoListBean> {

    private int toolbarHeight;
    private boolean isFromShoppingCart;

    public SpecialActivityHotAdapter(Context context, List<SpecialActivityInfo.MallActivityPageVoListBean> data, int height,boolean isFromShoppingCart) {
        super(context, data, R.layout.item_special_activity_hot);
        this.toolbarHeight = height;
        this.isFromShoppingCart = isFromShoppingCart;
    }

    @Override
    protected void bindDataHelper(QuickRcvHolder viewHolder, int position, SpecialActivityInfo.MallActivityPageVoListBean item) {
        RelativeLayout mRlContent = viewHolder.getView(R.id.rl_content);
        RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) mRlContent.getLayoutParams();
        SpecialActivityHotList hotList = GsonConvert.fromJson(item.getPageJson(), SpecialActivityHotList.class);
        if (hotList != null) {
            layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT;
            layoutParams.height = (int) NumberUtlis.mul(NumberUtlis.div(hotList.getHeight(), 1920), Utils.getScreenHeight() - toolbarHeight);
            mRlContent.setLayoutParams(layoutParams);
            ImageUtils.loadHotPic(Utils.returnUrlShow(hotList.getPagePic()), viewHolder.getView(R.id.iv_activity_bg));
            for (SpecialActivityHotList.GoodsListBean goodsListBean : hotList.getGoodsList()) {
                ImageView activityItem = new ImageView(mContext);
                //                activityItem.setScaleType(ImageView.ScaleType.FIT_XY);
                RelativeLayout.LayoutParams imageLayoutParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
                imageLayoutParams.width = (int) NumberUtlis.mul(NumberUtlis.div(goodsListBean.getWidth(), 1080), Utils.getScreenWidth());
                imageLayoutParams.height = (int) NumberUtlis.mul(NumberUtlis.div(goodsListBean.getHeight(), 1920), Utils.getScreenHeight() - toolbarHeight);
                imageLayoutParams.leftMargin = (int) NumberUtlis.mul(NumberUtlis.div(goodsListBean.getLeft(), 1080), Utils.getScreenWidth());
                imageLayoutParams.topMargin = (int) NumberUtlis.mul(NumberUtlis.div(goodsListBean.getTop(), 1920), Utils.getScreenHeight() - toolbarHeight);
                activityItem.setLayoutParams(imageLayoutParams);
                //                activityItem.setBackgroundResource(R.color.transparency);
                //                activityItem.setText(goodsListBean.getGoodsName());
                //                activityItem.setGravity(Gravity.CENTER);
                //                activityItem.setTextColor(mContext.getResources().getColor(R.color.color_FFFFFF));
                ImageUtils.loadHotPic(Utils.returnUrlShow(goodsListBean.getGoodsName()), activityItem);
                activityItem.setOnClickListener(v ->
                        Utils.startGoodsDetails((Activity) mContext, (int) goodsListBean.getGoodsId(), (int) goodsListBean.getGoodsSkuId(), isFromShoppingCart)
                );
                mRlContent.addView(activityItem);
            }
        }

    }
}
